package com.seven.system.controller.api;

import com.seven.enity.User;
import com.seven.system.service.UserService;
import com.seven.utils.JWTUtil;
import com.seven.vo.Result;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author longlong
 * @date 2024/3/6 15:45
 * description
 */
@RestController
@RequestMapping("/system/user")
public class UserController {

    @Resource
    private UserService userService;

    @GetMapping("/getName/{name}")
    public User getByName(@PathVariable String name){
        return userService.getByName(name);
    }

    @GetMapping(value = "/info")
    public Result getUserInfo(HttpServletRequest request, HttpServletResponse response){
        response.setContentType("application/json; charset=utf-8");
        String token = request.getHeader("token");
        String username = JWTUtil.parseToken(token);
        return new Result(2000,"获取成功",userService.getByName(username));
    }
}
